<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>

<body>
    <div id="app"></div>
    <template id="my-app">
        <h2>今天温度:{{temp}}度</h2>
        <h3>今天建议穿衣:{{suggestion}}</h3>
        <button @click="add">+</button>
        <button @click="minus">-</button>
    </template>
    <script>
        const App = {
            template: "#my-app",

            data() {
                const temp = 10
                return {
                    temp,
                }
            },
            methods: {
                add() {
                    this.temp += 5
                },
                minus() {
                    this.temp -= 5
                },
            },
            computed: {
                suggestion() {//响应式执行,当它依赖的数据源发生变更时
                    let res = '夹克'
                    if (this.temp >= 30) {
                        res = '卫衣'
                    } else if (this.temp > 5) {
                        res = '夹克'
                    } else if (this.temp <= 5) {
                        res = '羽绒服'
                    }
                    return res
                }
            }
        }
        Vue.createApp(App).mount('#app')
    </script>
</body>

</html>